<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <script>
        var inputDom = document.querySelector('input');
        // 键盘按下
        inputDom.onkeydown = function(){
            console.log('onkeydown')
        }
        // 键盘抬起
        inputDom.onkeyup = function(){
            console.log('onkeyup')
        }
        inputDom.onkeypress = function(){
            console.log('keypress触发')
        }
        //onkeydown 与onkeypress区别在于 onkeypress对于功能性(esc按键，方向键)按键无效
    </script>

</body>
</html>